--[[
	Galactica
	File: buy_stools.lua
]]

Galactica.Stools = {}

function Galactica.Stools.CheckBuyableStool(stool)
	for k, v in pairs(Galactica_BuyStools) do
		if(v == stool) then
			return true
		end
	end
	return false
end

function Galactica.Stools.GetStoolPrice(stool)
	for k, v in pairs(Galactica_BuyStools) do
		if(v == stool) then		
			return Galactica_BuyStoolsPrices[k]
		end
	end
end

function Galactica.Stools.BuyStool(ply, stool)
	if(Galactica.Stools.CheckBuyableStool(stool) == false) then
		Galactica.Nofity(ply, "This stool can't be brought")
		return
	elseif(table.HasValue(Galactica.Players[ply:SteamID()].Stools, stool)) then
		Galactica.Nofity(ply, "You already own that stool")
	elseif(tonumber(Galactica.GetMoney(ply)) >= tonumber(Galactica.Stools.GetStoolPrice(stool))) then
		Galactica.SetMoney(ply, Galactica.GetMoney(ply) - Galactica.Stools.GetStoolPrice(stool))
		Galactica.Nofity(ply, "You have brought the "..stool.." stool")
	else
		Galactica.Nofity(ply, "You do not have enough money for this stool")
		return
	end	
	Galactica.DataUpdate(ply)
	table.insert(Galactica.Players[ply:SteamID()].Stools, stool)
end

function Galactica.Stools.BuyStoolCommand(ply, cmd, args)
	if(args[1]) then
		Galactica.Stools.BuyStool(ply, string.lower(args[1]))
	else
		Galactica.Nofity(ply, "You did not specify a stool")
	end
end
concommand.Add("GalacticaBuyStool", Galactica.Stools.BuyStoolCommand)

function Galactica.Stools.CanTool(ply, tr, stool)
	if(table.HasValue(Galactica_BuyStools, stool) and table.HasValue(Galactica.Players[ply:SteamID()].Stools, stool) == false and ply:IsAdmin() == false) then
		Galactica.Nofity(ply, "This toolgun is restricted. You must buy it first")
		return false
	end
end
hook.Add("CanTool", "Galactica.Stools.CanTool", Galactica.Stools.CanTool)

function Galactica.Stools.PlayerSay(ply, saywhat)
	if(string.find(string.lower(saywhat), "/buystool")) then
		local saywhatsub = string.Trim(string.Replace(saywhat, "/buystool", ""))
		ply:ConCommand("GalacticaBuyStool "..tostring(saywhatsub))
	end
end
hook.Add("PlayerSay", "Galactica.Stools.PlayerSay", Galactica.Stools.PlayerSay)
